package leetcode.editor.cn;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Administrator
 * @description 剑指 Offer II 055. 二叉搜索树迭代器
 * @date 2023/3/25 0025
 */
public class BSTIterator {

    private int n = 0;
    private List<Integer> list;

    public BSTIterator(TreeNode root) {
        list = new LinkedList();
        helper(root, list);
    }

    private void helper(TreeNode root, List list) {
        if (root == null) {
            return;
        }
        helper(root.left, list);
        list.add(root.val);
        helper(root.right, list);
    }

    public int next() {
        return list.get(n++);
    }

    public boolean hasNext() {
        if (list.size() > n){
            return true;
        }
        return false;
    }
}
